//
//  UserAgreementViewController.m
//  SNS_Login-register
//
//  Created by hy on 2021/10/27.
//  Copyright © 2021 lzxuan. All rights reserved.
//

#import "UserAgreementViewController.h"
#import "HWGameMgr.h"
#import "HWConstant.h"
#import <WebKit/WebKit.h>

@interface UserAgreementViewController ()
@property (strong, nonatomic) WKWebView *webView;
@property (weak, nonatomic) IBOutlet UIView*webViewBg;
@property (weak, nonatomic) IBOutlet UIView*viewBg;

@end

@implementation UserAgreementViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)viewDidLayoutSubviews{
//    [self showWebViewWithUrl:_showUrl];
}
-(void)showWebViewWithUrl:(NSString*)url{
    
    if (_webView==NULL) {
        
        CGRect rect = CGRectMake(0, 0, self.viewBg.frame.size.width-20, self.viewBg.frame.size.height-30);
        _webView = [[WKWebView alloc] initWithFrame:rect];
        [self.webViewBg addSubview:_webView];
    }
//    [_webView loadHTMLString:@" " baseURL:nil];
//    [_webView evaluateJavaScript:@"document.body.innerHTML='';"completionHandler:^(id_Nullable response, NSError *_Nullable error) { }];
//    //1、生成请求体
    NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; // kPrivateUrl
    //2、webView加载请求体
    [_webView loadRequest:request];
}

- (void)clearWebView{
    if ( _webView!=NULL) {
        [ _webView evaluateJavaScript:@"document.body.innerHTML='';" completionHandler:^(id _Nullable,NSError * _Nullable error) {}];
    }
}

#pragma mark - 关闭
- (IBAction)closeBtnClick:(id)sender {
    [[HWGameMgr shared] hiddenUserAgreement];
}

//-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
//    [webView evaluateJavaScript:@"document.body.scrollHeight;" completionHandler:^(id _Nullable any, NSError * _Nullable error) {
////        NSString *heightStr = [NSString stringWithFormat:@"%@",any];
////         self.bgSCroller.contentSize = CGSizeMake(0, self.detailTable.contentSize.height + heightStr.floatValue);
////        self.webView.frame = CGRectMake(0, kMaxY(self.detailTable), self.webViewBg.bounds.size.width, heightStr.floatValue);
//        self.webView.frame = self.webViewBg.bounds;
//    }];
//}

@end
